package com.uls.web.controller.zsw;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.zsw.domain.ElectricityManage;
import com.uls.zsw.service.IElectricityManageService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 电源管理Controller
 * 
 * @author zsw
 * @date 2024-11-20
 */
@RestController
@RequestMapping("/zsw/electricity")
public class ElectricityManageController extends BaseController
{
    @Autowired
    private IElectricityManageService electricityManageService;

    /**
     * 查询电源管理列表
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricity:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElectricityManage electricityManage)
    {
        startPage();
        List<ElectricityManage> list = electricityManageService.selectElectricityManageList(electricityManage);
        return getDataTable(list);
    }

    /**
     * 导出电源管理列表
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricity:export')")
    @Log(title = "电源管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElectricityManage electricityManage)
    {
        List<ElectricityManage> list = electricityManageService.selectElectricityManageList(electricityManage);
        ExcelUtil<ElectricityManage> util = new ExcelUtil<ElectricityManage>(ElectricityManage.class);
        util.exportExcel(response, list, "电源管理数据");
    }

    /**
     * 获取电源管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricity:query')")
    @GetMapping(value = "/{electricityId}")
    public AjaxResult getInfo(@PathVariable("electricityId") Long electricityId)
    {
        return success(electricityManageService.selectElectricityManageByElectricityId(electricityId));
    }

    /**
     * 新增电源管理
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricity:add')")
    @Log(title = "电源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElectricityManage electricityManage)
    {
        System.out.println(electricityManage);
        return toAjax(electricityManageService.insertElectricityManage(electricityManage));
    }

    /**
     * 修改电源管理
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricity:edit')")
    @Log(title = "电源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElectricityManage electricityManage)
    {
        return toAjax(electricityManageService.updateElectricityManage(electricityManage));
    }

    /**
     * 删除电源管理
     */
    @PreAuthorize("@ss.hasPermi('zsw:electricity:remove')")
    @Log(title = "电源管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{electricityIds}")
    public AjaxResult remove(@PathVariable Long[] electricityIds)
    {
        return toAjax(electricityManageService.deleteElectricityManageByElectricityIds(electricityIds));
    }

    @PreAuthorize("@ss.hasPermi('zsw:electricity:getdi')")
    @GetMapping("/getdi/{DN}")
    public AjaxResult getDIByDN(@PathVariable("DN") String DN){
        return success(electricityManageService.getDIByDN(DN));
    }

    @PreAuthorize("@ss.hasPermi('zsw:electricity:getdn')")
    @GetMapping("/getdn/{DI}")
    public AjaxResult getDIByDN(@PathVariable("DI") Long DI){
        return success(electricityManageService.getDNByDI(DI));
    }
}
